-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat: Add Right-to-Left (RTL) layout support #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
This commit introduces a new feature enabling Right-to-Left (RTL) layout for docsify sites. Key changes: - **Configuration:** Added a new boolean option `rtl` (default: `false`) to `window.$docsify` configuration in `src/core/config.js`. Setting this to `true` enables RTL mode. - **Styling:** - Created `src/themes/shared/_rtl.css` with specific styles for RTL layout, including adjustments for text direction, sidebar positioning, and content margins. - Imported `_rtl.css` into `src/themes/shared/__index.css`. - **Behavior:** Modified `src/core/Docsify.js` to add a `rtl` class to the `<body>` element when `config.rtl` is true. This class activates the RTL-specific CSS rules. - **Testing:** Added a new end-to-end test suite in `test/e2e/rtl.test.js` to verify: - The `rtl` class is applied to the body. - The sidebar is positioned on the right. - Content margins are adjusted for the right-hand sidebar. - **Documentation:** Updated `docs/configuration.md` to document the new `rtl` option, its type, default value, and usage. This feature addresses your request for better RTL support, allowing you to create documentation sites that cater to RTL languages.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -25,6 +25,11 @@ export class Docsify extends Fetch( | |||
this.initRender(); // Render base DOM | |||
this.initEvent(); // Bind events | |||
this.initFetch(); // Fetch data | |||
|
|||
if (this.config.rtl) { | |||
document.body.classList.add('rtl'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of adding a class, what about using the dir
attribute?
<html dir="rtl">
and target the changes in the layout using that as the selector? [dir=rtl] .layout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @rrickay that using dir="rtl"
is more reasonable since it is the standard HTML attr for RTL contents layout.
But if it add-on on html
level for all contents, there is no place to change non-RTL content(img, code...etc) to place as LTR.
Maybe the styling on RTL should be more specific either configurable.
Summary
This commit introduces a new feature enabling Right-to-Left (RTL) layout for docsify sites.
Related issue, if any:
Close #2511
What kind of change does this PR introduce?
rtl
(default:false
) towindow.$docsify
configuration insrc/core/config.js
. Setting this totrue
enables RTL mode.src/themes/shared/_rtl.css
with specific styles for RTL layout, including adjustments for text direction, sidebar positioning, and content margins._rtl.css
intosrc/themes/shared/__index.css
.src/core/Docsify.js
to add artl
class to the<body>
element whenconfig.rtl
is true. This class activates the RTL-specific CSS rules.test/e2e/rtl.test.js
to verify:rtl
class is applied to the body.docs/configuration.md
to document the newrtl
option, its type, default value, and usage.For any code change,
Does this PR introduce a breaking change?
No
Tested in the following browsers: